<?php

namespace mpend\modules\pages\models;

use Yii;
use common\models\navigation\NavigationItem;
use common\models\navigation\Navigation;

/**
 * 班组记工本按日期统计模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class PageTabsSearch extends NavigationItem {

    /**
     * @var string 页面位置
     */
    public $position;

    public function rules() {
        return [
            ['position', 'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function buildQuery($alias = 't') {
        $query = static::find();
        if ($alias) {
            $query->alias($alias);
            $alias .= '.';
        }
        $query->active(static::STATUS_ACTIVE);
        $query->innerJoinWith('navigation navigation');
        $query->andWhere([
            'navigation.position' => $this->position,
            'navigation.deleted_at' => 0,
            'navigation.status' => Navigation::STATUS_ACTIVE,
        ]);
        $query->orderBy([
            $alias . 'listorder' => SORT_ASC,
        ]);
        $query->debug();
        return $query;
    }

    public function getTabname() {
        return strval($this->id);
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'title',
            'description',
            'componentName' => 'name',
            'icon',
            'badge',
            'mplink',
            'tabname',
        ];
    }

}
